!> author: 左志华
!> date: 2022-07-23
module test_master_time_m

    use testdrive, only: new_unittest, unittest_type, error_type, check
    use master_time_m
    implicit none
    private

    public :: collect_master_time

contains

    subroutine collect_master_time(test_suite)
        type(unittest_type), allocatable, intent(out) :: test_suite(:)

        allocate (test_suite, source=[ &
                  new_unittest("FUNC: now", test_now), &
                  new_unittest("FUNC: tioc", test_tioc), &
                  new_unittest("FUNC: bench", test_bench), &
                  new_unittest("FUNC: is_leap", test_is_leap) &
                  ])

    end subroutine collect_master_time

    subroutine test_now(error)
        type(error_type), allocatable, intent(out) :: error

        call check(error, len(now()), 23, "now() len")

    end subroutine test_now

    subroutine test_tioc(error)
        type(error_type), allocatable, intent(out) :: error
        real :: t
        call tic()
        call toc(t)
        call check(error, t, 0.0, "tic() toc()")
    end subroutine test_tioc

    subroutine test_is_leap(error)
        type(error_type), allocatable, intent(out) :: error

        call check(error, is_leap(2008), .true., "is_leap(2008)")
        call check(error, is_leap(2022), .false., "is_leap(2009)")

    end subroutine test_is_leap

    subroutine test_bench(error)
        type(error_type), allocatable, intent(out) :: error

        call bench(add, N=10, msg="Benchmarking for `add`")

    contains

        subroutine add()
            integer :: x, y, z

            x = 1; y = 2
            z = x + y

        end subroutine add

    end subroutine test_bench

end module test_master_time_m
